﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataProvider;
using System.Data;
using System.Data.SqlClient;

namespace BusinessLayer
{
    public class TonKho:XL_Bang
    {

        private string _maVTU;
        public string MaVTU
        {
            get { return _maVTU; }
            set { _maVTU = value; }
        }

        private string _namThang;
        public string NamThang
        {
            get { return _namThang; }
            set { _namThang = value; }
        }
        public DataTable GetData(DateTime fromDate,DateTime toDate,string selectedMaVTU )
        {
            try
            {
                open();
                command = new System.Data.SqlClient.SqlCommand();
                command.CommandText = "LOAD_TONKHO";
                command.Parameters.AddWithValue("@FROMDATE", fromDate);
                command.Parameters.AddWithValue("@TODATE", toDate);
                command.Parameters.AddWithValue("@MAVTU", selectedMaVTU);
                command.Connection = connect;
                command.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter adapter = new SqlDataAdapter(command);
                DataTable table = new DataTable();
                adapter.Fill(table);
                close();
                return table;
            }
            catch (Exception)
            {
                return null;
            }
            finally
            {
                close();
                command.Dispose();
            }
        }

        public bool CapNhatTonKho()
        {
            try
            {
                open();
                command = new System.Data.SqlClient.SqlCommand();
                command.CommandText = "sp_TONKHO_CAPNHATTONGSL_NX";
                command.Parameters.AddWithValue("@NAMTHANG", _namThang);
                command.Parameters.AddWithValue("@MA_VT", _maVTU);
                command.Connection = connect;
                command.CommandType = CommandType.StoredProcedure;
                command.ExecuteNonQuery();
                close();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
            finally
            {
                command.Dispose();
                close();
            }
        }


    }
}

